#! /bin/sh
set -e

PREREQ=""
prereqs()
{
	echo "$PREREQ"
}

case $1 in
	prereqs)
		prereqs
		exit 0
		;;
esac

filename="/usr/share/initramfs-tools/scripts/local"
filename_initramfs="${DESTDIR}/scripts/local"
oldvalue='mount ${roflag} -o loop -t ${FSTYPE} ${LOOPFLAGS} "/host/${LOOP#/}" '
newvalue='loopdev=`losetup -f`; losetup ${loopdev} "/host/${LOOP#/}"; mount ${roflag} -t ${FSTYPE} ${LOOPFLAGS} ${loopdev} '

if [ -f $filename ]; then
	if cat $filename | grep "$oldvalue" >/dev/null; then
		sed -i "s%$oldvalue%$newvalue%g" $filename
                if [ -f $filename_initramfs ]; then
			cp $filename $filename_initramfs
		fi
	fi
fi

exit 0
